﻿//Write a method that asks the user for his name and prints “Hello, <name>” (for example, “Hello, Peter!”). Write a program to test this method.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AskForName
{
    class AskForName
    {
        public static void Main()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(AskForNameMethod());
            if (checkName(sb))
            {
                Console.WriteLine("Hello, {0}!", sb.ToString());
            }
            else
                Console.WriteLine("Incorect Name string");
        }

        public static string AskForNameMethod()
        {
            Console.WriteLine("Write your name:"); ;
            return (Console.ReadLine());
        }
        static bool checkName(StringBuilder sb)
        {
            bool result = true;

            for (int i = 0; i < sb.Length; i++)
            {
                result = (Char.IsLetter(sb[i]) || Char.IsWhiteSpace(sb[i]));
                if (result == false)
                    break;
            }
            return result;
        }
    }
}
